import request from 'request';
import Promise from 'bluebird';
import iconv from 'iconv-lite';

const fetch = {
	request: Promise.promisify(request),
	get: Promise.promisify(request.get),
	getAndDecode: function (url) {
		return new Promise((resolve, reject) => {
			request(url).pipe(iconv.decodeStream('gb2312')).collect((err, body) => {
				if (err) reject(err);
				resolve(body);
			});
		});
	}
};

export default fetch;

